<template>
  <a-drawer
      :title="title"
      :width="800"
      placement="right"
      :closable="false"
      @close="close"
      :visible="visible"
  >

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="个人信息ID">
          <a-input placeholder="请输入个人信息ID" v-decorator="['personalinfoid', validatorRules.personalinfoid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="姓名">
          <a-input placeholder="请输入姓名" v-decorator="['personalname', validatorRules.personalname ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="性别">
          <a-input placeholder="请输入性别" v-decorator="['genderid', validatorRules.genderid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯省">
          <a-input placeholder="请输入籍贯省" v-decorator="['provinceid', validatorRules.provinceid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯市">
          <a-input placeholder="请输入籍贯市" v-decorator="['cityid', validatorRules.cityid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="籍贯区/县">
          <a-input placeholder="请输入籍贯区/县" v-decorator="['districtid', validatorRules.districtid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="手机">
          <a-input placeholder="请输入手机" v-decorator="['phone', validatorRules.phone ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="电话">
          <a-input placeholder="请输入电话" v-decorator="['tel', validatorRules.tel ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="微信">
          <a-input placeholder="请输入微信" v-decorator="['wechat', validatorRules.wechat ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="邮箱">
          <a-input placeholder="请输入邮箱" v-decorator="['email', validatorRules.email ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="年龄段">
          <a-input placeholder="请输入年龄段" v-decorator="['agegroupid', validatorRules.agegroupid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="学校/学历">
          <a-input placeholder="请输入学校/学历" v-decorator="['schooldegreeid', validatorRules.schooldegreeid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="工作/专业">
          <a-input placeholder="请输入工作/专业" v-decorator="['jobprofessionalid', validatorRules.jobprofessionalid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="个人荣誉">
          <a-input placeholder="请输入个人荣誉" v-decorator="['personalhonorid', validatorRules.personalhonorid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="个人爱好">
          <a-input placeholder="请输入个人爱好" v-decorator="['personalhobbiesid', validatorRules.personalhobbiesid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="互动标签">
          <a-input placeholder="请输入互动标签" v-decorator="['interactivetagid', validatorRules.interactivetagid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="Linker">
          <a-input placeholder="请输入Linker" v-decorator="['linkerid', validatorRules.linkerid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新人">
          <a-input placeholder="请输入最近更新人" v-decorator="['updatebyid', validatorRules.updatebyid ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="最近更新日期">
          <a-input placeholder="请输入最近更新日期" v-decorator="['ts', validatorRules.ts ]" />
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="状态">
          <a-input placeholder="请输入状态" v-decorator="['datastatus', validatorRules.datastatus ]" />
        </a-form-item>
		
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "PersonalInfoModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        personalinfoid:{rules: [{ required: true, message: '请输入个人信息ID!' }]},
        personalname:{rules: [{ required: true, message: '请输入姓名!' }]},
        genderid:{rules: [{ required: true, message: '请输入性别!' }]},
        provinceid:{rules: [{ required: true, message: '请输入籍贯省!' }]},
        cityid:{rules: [{ required: true, message: '请输入籍贯市!' }]},
        districtid:{rules: [{ required: true, message: '请输入籍贯区/县!' }]},
        phone:{rules: [{ required: true, message: '请输入手机!' }]},
        tel:{rules: [{ required: true, message: '请输入电话!' }]},
        wechat:{rules: [{ required: true, message: '请输入微信!' }]},
        email:{rules: [{ required: true, message: '请输入邮箱!' }]},
        agegroupid:{rules: [{ required: true, message: '请输入年龄段!' }]},
        schooldegreeid:{rules: [{ required: true, message: '请输入学校/学历!' }]},
        jobprofessionalid:{rules: [{ required: true, message: '请输入工作/专业!' }]},
        personalhonorid:{rules: [{ required: true, message: '请输入个人荣誉!' }]},
        personalhobbiesid:{rules: [{ required: true, message: '请输入个人爱好!' }]},
        interactivetagid:{rules: [{ required: true, message: '请输入互动标签!' }]},
        linkerid:{rules: [{ required: true, message: '请输入Linker!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        },
        url: {
          add: "/robot/personalInfo/add",
          edit: "/robot/personalInfo/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'personalinfoid','personalname','genderid','provinceid','cityid','districtid','phone','tel','wechat','email','agegroupid','schooldegreeid','jobprofessionalid','personalhonorid','personalhobbiesid','interactivetagid','linkerid','updatebyid','ts','datastatus'))
		  //时间格式化
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>